<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scaleable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>rem</title>
    <style>
        html {
            font-size: 17px;
        }
        .box {
            width: 10rem;
            height: 10rem;
            background-color: red;
        }
        .text {
            color: #fff;
            font-size: 16px;
        }
        @media screen and (max-width: 360px) and (min-width:321px) {
            html {
                font-size: 20px;
            }
        }
        @media screen and (max-width: 320px) {
            html {
                font-size: 24px;
            }
        }
    </style>
    <script>
        window.onload = function() {
            let htmlWidth = document.documentElement.clientWidth || document.body.clientWidth;
            console.log(htmlWidth);
            let htmlDom = document.getElementsByTagName('html')[0];
            htmlDom.style.fontSize = htmlWidth / 10 + 'px';
        };
    </script>
</head>
<body>
    <div class="box">
        <p class="text">hello rem</p>
    </div>
</body>
</html>